package cn.com.connext.scrm.repository.master;

import cn.com.connext.scrm.domain.master.Comment;
import cn.com.connext.scrm.domain.master.TaskRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by YANG205 on 2018/6/27.
 */
@Repository
public interface TaskRecordRepository extends JpaRepository<TaskRecord, String>, JpaSpecificationExecutor {
    @Query(value = "select a.* from point_task_record a where  user_id= :userId AND task_type = :taskType ", nativeQuery = true)
    List<TaskRecord> findByUserIdAndTaskType(@Param("userId") String userId,@Param("taskType") Integer taskType);

    @Query(value = "select a.* from point_task_record a where user_id= :userId AND task_type = :taskType AND to_days(create_time) = to_days(now()) ", nativeQuery = true)
    List<TaskRecord> findByUserIdAndTaskTypeAnAndCreateTime(@Param("userId") String userId,@Param("taskType") Integer taskType);

    @Query(value = "select a.* from point_task_record a where  user_id= :userId AND task_type = :taskType AND date_format(create_time,'%Y-%m')=date_format(now(),'%Y-%m') ", nativeQuery = true)
    List<TaskRecord> findByUserIdAndTaskTypeAnAndMonth(@Param("userId") String userId,@Param("taskType") Integer taskType);

    @Query(value = "select a.* from point_task_record a where user_id= :userId AND to_days(create_time) = to_days(now()) ", nativeQuery = true)
    List<TaskRecord> findByUserIdAndCreateTime(@Param("userId") String userId);
}
